
import type { ChannelItem, ChannelResData } from "@/types/data";
import axios from "axios";
import { defineStore } from "pinia";
import { computed, ref } from "vue";


// 命名规范 use仓库名Store
// defineStore相当于vue2中的new Vuex.Store()
export const useCounterStore = defineStore('counter', () => {
  // 相当于state
  const count = ref(0)
  // 相当于 getters
  const doubleCount = computed(() => count.value * 2)
  // 相当于mutilations和actions
  const add = () => count.value++
  const cut = () => count.value--

  const channelList = ref<ChannelItem[]>([])
  const getChannelList = async () => {
    const res = await axios.get<ChannelResData>('http://geek.itheima.net/v1_0/channels')
    channelList.value = res.data.data.channels
  }

  return { count, doubleCount, add, cut, channelList, getChannelList }
})